import axios from "axios";

const http = axios.create({
  baseURL: "https://gaimusicservice.cpolar.top/gateway",
  headers: {
    "Content-type": "application/json",
  },
});


// 获取账户余额
const getBalance = () => {
  return new Promise((resolve, reject) => {
    resolve(0);
  });
};

// 查询音乐
// id: 音乐ID数组
const query = (id) => {
  const idsStr = id.join(",");
  console.log('idsStr::::', idsStr)
  return http
    .get("/query", {
      params: {
        ids: idsStr,
      },
    })
    .then((response) => {
      return response.data;
    });
};

// 通过描述生成音乐
const generate = (description, isInstrumental = false, model = "chirp-v3-0") => {
  const url = "/generate/v2";
  const data = {
    gpt_description_prompt: description,
    make_instrumental: isInstrumental,
    mv: model,
    prompt: "",
    task: "",
  };

  return http.post(url, JSON.stringify(data)).then(response => {
    return response.data;
  });
};

const MusicService = {
  getBalance,
  query,
  generate,
};

export default MusicService;
